{% extends 'kingadmin/index.html' %}
{% load admin_tags %}

{% block page-title-text %}
{{ model_verbose_name }}
{% endblock %}

{% block searchbox %}{% endblock %}

{% block breadcrumb %}
    <ol class="breadcrumb">
        <li><a href="{% url 'table_index' %}">Home</a></li>
        <li><a href="{% url 'app_tables'  app_name %}">{{ app_name|capfirst }}</a></li>

        <li><a href="{% url 'table_list' app_name model_name %}">{{ model_verbose_name }}</a></li>
        <li class="active"> 添加 {{ model_verbose_name }}</li>
    </ol>

{#    <div class="row" style="margin-bottom: 20px" >#}
{##}
{#        <ol class="breadcrumb">#}
{#          <li><a href="/kingadmin/">Home</a></li>#}
{#          <li><a href="/kingadmin/{% app_name %}">{% app_name %}</a></li>#}
{#          <li class="active">{% get_model_verbose_name admin_obj.model%}</li>#}
{#        </ol>#}
{##}
{#       <a href="{{ request.path }}add/" class="btn btn-sm btn-success pull-right">+Add {% get_model_verbose_name admin_obj.model%} </a>#}
{##}
{#    </div>#}


 {% endblock %}

{% block page-content %}
     {% include 'kingadmin/filter_search_box.html' %}

     <script src="/static/kingadmin/js/kingadmin/filter_horizontal.js"></script>


    {% check_pop_up_window request form_obj %}

    <div class="panel">
        <div class="panel-heading">
            <h3 class="panel-title">Add {{ table_obj.model_verbose_name }}
                <a  href="{% url 'table_list' app_name model_name %}" class="btn btn-sm btn-info btn-labeled fa fa-mail-reply pull-right">
                   返回 {{ table_obj.model_verbose_name }}
                </a>
            </h3>
        </div>
        <form method="post" onsubmit="return CheckSelectedOptions()" class=" form-horizontal form-padding">{% csrf_token %}
    {#    <form method="post" class=" form-horizontal form-padding">{% csrf_token %}#}
            <div class="panel-body">
                {% if form_obj.errors%}
                    <div class="alert alert-danger media fade in">
                        <strong>表单错误!</strong> {% get_form_global_error form_obj.errors %}
                    </div>
    {#                {% printf form_obj.errors %}#}
                {% endif %}
                {% for field in form_obj %}
                    <div class="form-group">
                        {%if field.field.required%}
                            <label class="col-md-2 control-label">
                                <b>{{field.label}}</b>
                            </label>
                        {% else %}
                            <label class="col-md-2 control-label">
                               {{field.label}}
                            </label>
                        {% endif %}
                        <div class="col-md-9">
                            {% if field.name not in admin_class.filter_horizontal %}
                                {{ field }}
                                {% add_fk_search_btn form_obj field %}
                                {% add_new_obj_btn form_obj field %}

    {#                            {% decorate_date_field form_obj field %}#}
                                {% if field.errors %}
                                    <span style="color: red">{{ field.errors }}</span>
                                {% endif %}
                            {% else %}
                                {% include 'kingadmin/filter_horizontal_multi_select.html' %}
                                {% if field.errors %}
                                    <span style="color: red">{{ field.errors }}</span>
                                {% endif %}
                            {% endif %}
                        </div>
                    </div>
                {% endfor %}


            </div> <!--end panel-body-->
            <div class="panel-footer">
                <div class="row">

                    <div class="col-sm-4 col-lg-offset-1 ">
                        <button class="btn btn-info  "  type="submit">Add</button>
                    </div>
                    <div class="col-sm-6 ">
                        <button class="btn btn-success " name="_continue" type="submit">Save and continue editing</button>
                        &nbsp;
                        <button type="submit" class="btn btn-info  " name="_add_another"   >Save and add another</button>

                    </div>

                </div>
            </div>
        </form>
    </div>

{% endblock %}